"use strict";
/* Controllers */
app.controller("yarnApplicationReportController", ['$scope', '$location', '$rootScope', '$routeParams', 'yarnApplicationReportService', function ($scope, $location, $rootScope, $routeParams, yarnApplicationReportService) {

    var vm = $scope.vm = {};

    vm.p = {};
    vm.result = {};

    vm.p.clusterName = $routeParams.cluster;
    vm.p.queue = $routeParams.queue;
    vm.p.access = $routeParams.access;
    vm.p.ds0 = $routeParams.ds0;
    vm.p.ds1 = $routeParams.ds1;

    var errorFn = function (result) {
        alert(result);
    };

    $scope.searchYarnApplication = function (t) {
        var vm = $scope.vm;
        $scope.listYarnApplication();
    };

    $scope.listYarnApplication = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var param = vm.p;
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        yarnApplicationReportService.listYarnApplication(param, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listYarnApplication();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('yarnApplicationReportService', ['ajaxService', function (ajaxService) {

    this.listYarnApplication = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_application/listYarnApplicationReport.do", successFunction, errorFunction);
    };

}]);

function subBillStatusFormatter(value, row, index) {
    if (value == null) {
        return "-";
    }
    switch (value) {
        case 0:
        case 1:
            return "待接单";
        case 2:
            return "待发货";
        case 3:
            return "已收货";
        case 4:
            return "待结算";
        case 5:
            return "已完成";
        case 6:
            return "已取消";
        case 7:
            return "拒收";
        default:
            return "-";
    }
}

function payTypeFormatter(value, row, index) {
    if (value == null) {
        return "-";
    }
    switch (value) {
        case 0:
        case 1:
            return "货到付款";
        case 2:
            return "账期支付";
        case 3:
            return "线上支付";
        default:
            return "-";
    }
}

function paymentWayFormatter(value, row, index) {
    if (value == null) {
        return "-";
    }
    switch (value) {
        case 0:
            return "-";
        case 1:
            return "微信付款";
        case 2:
            return "支付宝付款";
        case 3:
            return "银联支付";
        case 4:
            return "现金";
        case 5:
            return "支票";
        case 6:
            return "快捷支付";
        case 7:
            return "余额支付";
        case 8:
            return "微信扫码";
        case 9:
            return "支付宝扫码";
        case 10:
            return "微信公众号";
        case 11:
            return "优惠券支付";
        case 12:
            return "卡支付";
        default:
            return "-";
    }
}

function convertStatusFormatter(value, row, index) {
    if (value == null) {
        return "-";
    }
    switch (value) {
        case 0:
            return "未转换";
        case 1:
            return "转换完成";
        case 2:
            return "转换失败";
        default:
            return "-";
    }
}


function appReportIDFmt(value, row, index) {// /profiling/:groupID/:shopID/:saasOrderID
    return [
        '<a href="#/star/order/cost_report_detail/', value, '" target="_blank">', " <u>查看明细</u>" , '</a>'
    ].join('');
}
